package myky.com.doctorapp.ui


import android.os.Bundle
import android.support.v7.widget.LinearLayoutManager
import android.view.View
import com.chad.library.adapter.base.BaseQuickAdapter
import com.gyf.barlibrary.ImmersionBar
import com.scwang.smartrefresh.layout.api.RefreshLayout
import com.scwang.smartrefresh.layout.listener.OnRefreshLoadMoreListener
import kotlinx.android.synthetic.main.activity_doctor_list.*
import kotlinx.android.synthetic.main.activity_follow_doctor_list.*
import kotlinx.android.synthetic.main.activity_follow_doctor_list.view.*
import myky.com.doctorapp.R
import myky.com.doctorapp.adapter.FollowDoctorListAdapter
import myky.com.doctorapp.base.BaseActivity
import myky.com.doctorapp.contract.FollowDoctorListContract
import myky.com.doctorapp.entity.FollowDoctorEntity
import myky.com.doctorapp.presenter.FollowDoctorListPresenter
import myky.com.doctorapp.utils.Constants

/**
 * Description: 随访医生列表
 * @author wuyang
 * Created by 2019/3/18 17:09
 */
class FollowDoctorListActivity : BaseActivity<FollowDoctorListPresenter, List<FollowDoctorEntity.DataBean>>(),FollowDoctorListContract.View ,OnRefreshLoadMoreListener,BaseQuickAdapter.OnItemChildClickListener{



    lateinit var doctorList: MutableList<FollowDoctorEntity.DataBean>
    lateinit var followAdapter:FollowDoctorListAdapter
    var current:Int=1
    override fun getPresenter(): FollowDoctorListPresenter = FollowDoctorListPresenter()
    override fun reloadActivity() {

    }

    override fun injectTarget(): View=findViewById(R.id.follow_doctor_list_lin)

    override fun initData() {
        mPresenter.pgetFollowDoctorList(current)
    }

    override fun initView() {
        ImmersionBar.with(this)
                .statusBarColor(R.color.white)
                .titleBar(R.id.follow_doctor_list_title)
                .init()
        conmonTitleTextViews.text=resources.getString(R.string.follow_doctor_list)
        doctorList=ArrayList()
        followAdapter= FollowDoctorListAdapter(doctorList)
        follow_doctor_list_recycler.layoutManager=LinearLayoutManager(this)
        follow_doctor_list_recycler.adapter=followAdapter
        followAdapter.onItemChildClickListener=this
        follow_doctor_list_refresh.setOnRefreshLoadMoreListener(this)
        backLayout_doctor.setOnClickListener { finish() }
    }
    override fun onItemChildClick(adapter: BaseQuickAdapter<*, *>?, view: View?, position: Int) {
        var doctorid = doctorList[position].doctorid
        var bundle=Bundle()
        bundle.putInt(Constants.DOCTORID,doctorid)
        startActivity(FollowRecordListActivity::class.java,bundle)
    }
    override fun getContenView(): Int =R.layout.activity_follow_doctor_list


    override fun showDataSuccess(datas: List<FollowDoctorEntity.DataBean>) {

        if (datas==null|| datas.isEmpty()){
            if (current==1){
                showEmptyView(getXmlString(R.string.new_case_popwindow_empty))
            }else{
                follow_doctor_list_refresh.finishLoadMoreWithNoMoreData()
            }
        }
        if (datas!=null) {
            doctorList.addAll(datas)
            followAdapter.notifyDataSetChanged()
        }
        follow_doctor_list_refresh.finishLoadMore(10)
        follow_doctor_list_refresh.finishRefresh(10)
    }

    override fun onLoadMore(refreshLayout: RefreshLayout) {
        current++
        mPresenter.pgetFollowDoctorList(current)
    }

    override fun onRefresh(refreshLayout: RefreshLayout) {
        current=1
        doctorList.clear()
        mPresenter.pgetFollowDoctorList(current)
    }
}
